package com.wms.shop.service.impl;

import java.util.List;
import java.util.Arrays;
import com.wms.common.core.utils.DateUtils;
import com.wms.shop.domain.Banner;
import com.wms.shop.mapper.BannerMapper;
import com.wms.shop.service.IBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wms.common.core.utils.SecurityUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * 首页banner图Service业务层处理
 *
 * @author zzm
 * @date 2021-12-05
 */
@Service
public class BannerServiceImpl implements IBannerService
{
    @Autowired
    private BannerMapper bannerMapper;

    /**
     * 查询首页banner图
     *
     * @param id 首页banner图ID
     * @return 首页banner图
     */
    @Override
    public Banner selectBannerById(Long id)
    {
        return bannerMapper.selectById(id);
    }

    /**
     * 查询首页banner图列表
     *
     * @param banner 首页banner图
     * @return 首页banner图
     */
    @Override
    public List<Banner> selectBannerList(Banner banner)
    {
        QueryWrapper queryWrapper = new QueryWrapper();
        return bannerMapper.selectList(queryWrapper);
    }

    /**
     * 新增首页banner图
     *
     * @param banner 首页banner图
     * @return 结果
     */
    @Override
    public int insertBanner(Banner banner)
    {
        banner.setDelFlag(false);
        banner.setCreateBy(SecurityUtils.getUsername());
        banner.setCreateTime(DateUtils.getNowDate());
        return bannerMapper.insert(banner);
    }

    /**
     * 修改首页banner图
     *
     * @param banner 首页banner图
     * @return 结果
     */
    @Override
    public int updateBanner(Banner banner)
    {
        banner.setUpdateBy(SecurityUtils.getUsername());
        banner.setUpdateTime(DateUtils.getNowDate());
        return bannerMapper.updateById(banner);
    }

    /**
     * 批量删除首页banner图
     *
     * @param ids 需要删除的首页banner图ID
     * @return 结果
     */
    @Override
    public int deleteBannerByIds(Long[] ids)
    {
        Banner banner = new Banner();
        banner.setDelFlag(Boolean.TRUE);
        banner.setUpdateTime(DateUtils.getNowDate());
        banner.setUpdateBy(SecurityUtils.getUsername());
        QueryWrapper<Banner> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id",Arrays.asList(ids));
        return bannerMapper.update(banner, queryWrapper);
    }

    /**
     * 删除首页banner图信息
     *
     * @param id 首页banner图ID
     * @return 结果
     */
    @Override
    public int deleteBannerById(Long id)
    {
        return bannerMapper.deleteById(id);
    }
}